package com.wq.qa.contorller;

import com.wq.common.entity.PageResult;
import com.wq.common.entity.Result;
import com.wq.common.entity.StatusCode;
import com.wq.qa.entity.Problem;
import com.wq.qa.service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("problem")
@CrossOrigin
public class ProblemController {
    @Autowired
    private ProblemService problemService;

    @GetMapping("{id}")
    public Result queryById(@PathVariable String id) {
        Problem problem = problemService.findById(id);
        return new Result(true, StatusCode.OK, "查询成功", problem);
    }

    @GetMapping
    public Result findAll() {
        List<Problem> all = problemService.findAll();
        return new Result(true, StatusCode.OK, "查询成功", all);
    }

    @GetMapping("latest/{labelid}")
    public Result findLatest(@PathVariable String labelid, @RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "size", defaultValue = "5") int size) {
        PageResult latest = problemService.findLatest(labelid, page, size);
        return new Result(true, StatusCode.OK, "最新问题查询成功", latest);
    }

    @GetMapping("hot/{labelid}")
    public Result findHot(@PathVariable String labelid, @RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "size", defaultValue = "5") int size) {
        PageResult latest = problemService.findHot(labelid, page, size);
        return new Result(true, StatusCode.OK, "热门回答问题查询成功", latest);
    }

    @GetMapping("wait/{labelid}")
    public Result findWait(@PathVariable String labelid, @RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "size", defaultValue = "5") int size) {
        PageResult latest = problemService.findWait(labelid, page, size);
        return new Result(true, StatusCode.OK, "等待回答问题查询成功", latest);
    }
}
